package com.class04.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * @ClassDescription:
 * 业务层配置类：service ，aop，tx
 * 1.扫描service
 * 2.开启aop主机的支持aspect:
 * @Before  @After @AfterReturning  @AfterThrowing
 * @Around @Aspect  @Order指定切面类优先级
 * 3.tx声明事务管理：3.1、对应的事务管理器实现[TransactionManagement DataSource... Hibernate...jpa....]
 * 3.2、开启事务注解支持 @Transactional
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/20 15:37
 */
@Configuration
@EnableAspectJAutoProxy
@EnableTransactionManagement
@ComponentScan("com.class04.service")
public class ServiceJavaConfig {
    @Bean
    public TransactionManager transactionManager(DataSource dataSource){
        DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(dataSource);
        return dataSourceTransactionManager;
    }
}
